<?php
namespace App\Services;

use Illuminate\Support\Facades\Redis;

class CommonServices{
    // Object转array
    static public function object_array($array){
        if(is_object($array)) {
            $array = (array)$array;
        }if(is_array($array)) {
            foreach($array as $key=>$value) {
                $array[$key] = self::object_array($value);
            }
        }

        return $array;
    }

    // 写入redis
    static public function redis_set($name,$value){
        $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
        return Redis::set($name,$value);
    }

    // 读取redis缓存
    static public function redis_get($name){
        return json_decode(Redis::get($name),true);
    }
}